package IOTest;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileReaderTest {
    public static void main(String[] args) {
        File file = new File("testfile.txt");
        if (file.exists()) {
            FileReader fr = null;
            StringBuilder sb = new StringBuilder();
            try {
                fr = new FileReader(file);
                char[] cbuf = new char[100];
                int len;
                while ((len = fr.read(cbuf)) != -1) {
                    sb.append(cbuf, 0, len);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                // 关闭流
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                System.out.println(sb.toString());
            }

        }
    }

}
